package org.eiahe.hr.salary.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.utils.StringUtils;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.core.validate.QueryGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.eiahe.hr.salary.domain.bo.SocialInsurancePaymentBo;
import org.eiahe.hr.salary.domain.vo.SocialInsurancePaymentVo;
import org.eiahe.hr.salary.service.ISocialInsurancePaymentService;
import org.ehe.common.excel.utils.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 社保缴纳Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/salary/socialInsurance")
public class SocialInsurancePaymentController extends BaseController {

    private final ISocialInsurancePaymentService iSocialInsurancePaymentService;

    /**
     * 查询社保缴纳列表
     */
    @SaCheckPermission("salary:socialInsurance:list")
    @GetMapping("/list")
    public TableDataInfo<SocialInsurancePaymentVo> list(SocialInsurancePaymentBo bo, PageQuery pageQuery) {
        return iSocialInsurancePaymentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出社保缴纳列表
     */
    @SaCheckPermission("salary:socialInsurance:export")
    @Log(title = "社保缴纳", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SocialInsurancePaymentBo bo, HttpServletResponse response) {
        List<SocialInsurancePaymentVo> list = iSocialInsurancePaymentService.queryList(bo);
        ExcelUtil.exportExcel(list, "社保缴纳数据", SocialInsurancePaymentVo.class, response);
    }

    /**
     * 获取社保缴纳详细信息
     *
     * @param paymentId 主键
     */
    @SaCheckPermission("salary:socialInsurance:query")
    @GetMapping("/{paymentId}")
    public R<SocialInsurancePaymentVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("paymentId") Long paymentId) {
        return R.ok(iSocialInsurancePaymentService.queryById(paymentId));
    }

    /**
     * 新增社保缴纳
     */
    @SaCheckPermission("salary:socialInsurance:add")
    @Log(title = "社保缴纳", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SocialInsurancePaymentBo bo) {
        return toAjax(iSocialInsurancePaymentService.insertByBo(bo));
    }

    /**
     * 修改社保缴纳
     */
    @SaCheckPermission("salary:socialInsurance:edit")
    @Log(title = "社保缴纳", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SocialInsurancePaymentBo bo) {
        return toAjax(iSocialInsurancePaymentService.updateByBo(bo));
    }

    /**
     * 删除社保缴纳
     *
     * @param paymentIds 主键串
     */
    @SaCheckPermission("salary:socialInsurance:remove")
    @Log(title = "社保缴纳", businessType = BusinessType.DELETE)
    @DeleteMapping("/{paymentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] paymentIds) {
        return toAjax(iSocialInsurancePaymentService.deleteWithValidByIds(Arrays.asList(paymentIds)));
    }
}
